﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;

namespace ZDT.UI.Frm
{
    public class CheckCodeForm:System.Windows.Forms.Form
    {
        private System.Windows.Forms.PictureBox checkCodePic;
        private System.Windows.Forms.Button okBtn;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox checkCodeTxt;
        private System.Windows.Forms.Button resetBtn;

        public string CheckCode = string.Empty;
        [BrowsableAttribute(true)]
        [DataObjectFieldAttribute(true)]
        [ListBindableAttribute(true)]
        [DefaultValue("http://www.baidu.com")]
        [Description("图片地址")]
        public string Url { get; set; }
        public CheckCodeForm():base()
        {
            Url = string.Empty;
            InitializeComponent();
            this.TopLevel = true;
            this.TopMost = true;
            this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            //this.CenterToParent();
            this.ControlBox = false;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        }

        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.checkCodePic = new System.Windows.Forms.PictureBox();
            this.okBtn = new System.Windows.Forms.Button();
            this.checkCodeTxt = new System.Windows.Forms.TextBox();
            this.resetBtn = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.checkCodePic)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(13, 13);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(77, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "输入验证码：";
            // 
            // checkCodePic
            // 
            this.checkCodePic.Location = new System.Drawing.Point(15, 40);
            this.checkCodePic.Name = "checkCodePic";
            this.checkCodePic.Size = new System.Drawing.Size(136, 63);
            this.checkCodePic.TabIndex = 1;
            this.checkCodePic.TabStop = false;
            // 
            // okBtn
            // 
            this.okBtn.Location = new System.Drawing.Point(171, 47);
            this.okBtn.Name = "okBtn";
            this.okBtn.Size = new System.Drawing.Size(75, 23);
            this.okBtn.TabIndex = 2;
            this.okBtn.Text = " 确定";
            this.okBtn.UseVisualStyleBackColor = true;
            this.okBtn.Click += new System.EventHandler(this.okBtn_Click);
            // 
            // checkCodeTxt
            // 
            this.checkCodeTxt.Location = new System.Drawing.Point(96, 8);
            this.checkCodeTxt.Name = "checkCodeTxt";
            this.checkCodeTxt.Size = new System.Drawing.Size(150, 21);
            this.checkCodeTxt.TabIndex = 3;
            // 
            // resetBtn
            // 
            this.resetBtn.Location = new System.Drawing.Point(171, 76);
            this.resetBtn.Name = "resetBtn";
            this.resetBtn.Size = new System.Drawing.Size(75, 23);
            this.resetBtn.TabIndex = 4;
            this.resetBtn.Text = "重新获取";
            this.resetBtn.UseVisualStyleBackColor = true;
            this.resetBtn.Click += new System.EventHandler(this.resetBtn_Click);
            // 
            // CheckCodeForm
            // 
            this.AcceptButton = this.okBtn;
            this.ClientSize = new System.Drawing.Size(259, 125);
            this.ControlBox = false;
            this.Controls.Add(this.resetBtn);
            this.Controls.Add(this.checkCodeTxt);
            this.Controls.Add(this.okBtn);
            this.Controls.Add(this.checkCodePic);
            this.Controls.Add(this.label1);
            this.Name = "CheckCodeForm";
            this.Load += new System.EventHandler(this.CheckCodeForm_Load);
            ((System.ComponentModel.ISupportInitialize)(this.checkCodePic)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void okBtn_Click(object sender, EventArgs e)
        {
            CheckCode = checkCodeTxt.Text;
            this.Close();
        }

        private void resetBtn_Click(object sender, EventArgs e)
        {
            RefreshImage();
        }

        private void CheckCodeForm_Load(object sender, EventArgs e)
        {
            RefreshImage();
        }
        private void RefreshImage()
        {
            checkCodePic.ImageLocation = string.Empty;
            checkCodePic.ImageLocation = Url;
            checkCodePic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;

            ////等待时显示其他图片
            //checkCodePic.InitialImage = global::MainForm.Properties.Resources._36_1_;
            ////图片异步加载完成后的处理事件   
            //checkCodePic.LoadCompleted += new AsyncCompletedEventHandler(pictureBox_LoadCompleted);  

            ////图片加载时，显示等待光标   
            //checkCodePic.UseWaitCursor = true;
            ////采用异步加载方式   
            //checkCodePic.WaitOnLoad = false;
            ////开始异步加载   
            //checkCodePic.LoadAsync(Url);

        }
        //通用事件   
        private void pictureBox_LoadCompleted(object sender, AsyncCompletedEventArgs e)  
        {  
            //转换成PictureBox    
            PictureBox pi = (PictureBox)sender;  
            //图片加载完成后，将光标恢复   
            pi.UseWaitCursor = false;  
        }  

    }
}
